﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Business.WEB;
using DataAccess;
using Model;

namespace AirlinePilotAcedemy_WEB
{
    public partial class ConfirmInscriptionSubject : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {

            if (!Page.IsPostBack)
            {
                if (!User.Identity.IsAuthenticated)
                {
                    Response.Redirect("Login.aspx?");
                }


                codMateriaL.Text = Request["codMateria"];
                siglaTB.Text = Request["sigla"];
                nombreTB.Text = Request["nombre"];
                creditosTB.Text = Request["creditos"];
                descripcionTB.Text = Request["descripcion"];
            }
        }

        protected void ConfirmB_Click(object sender, EventArgs e)
        {
            User user = UserDataAccess.GetUserByUsername(User.Identity.Name);
            if (CanITakeSubject(user.Ci, Convert.ToInt64(this.codMateriaL.Text)))
            {
                //DateTime.Today.Date.Month.ToString()-->first option for "string gestion"
                SubjectConfirmationManager.NewInscription(user.Ci, Convert.ToInt64(this.codMateriaL.Text), getMonth(DateTime.Today)+ "-" + DateTime.Today.Year.ToString());
                Response.Write("<script>alert('Inscripcion satisfactoria a la materia seleccionada!!!'); window.location.href = 'TeacherMenu.aspx';</script>");
            }
            Response.Write("<script>alert('Usted ya esta inscrito a esa Materia!!!'); window.location.href = 'TeacherMenu.aspx';</script>");
        }
        protected bool CanITakeSubject(int studentId,long codMateria)
        {
            return SubjectConfirmationManager.CanITakeSubject(studentId,codMateria);
        }
        protected string getMonth(DateTime selectDate)
        {
            if (selectDate.Date.Month == 1)
                return "Enero";
            if (selectDate.Date.Month == 2)
                return "Febrero";
            if (selectDate.Date.Month == 3)
                return "Marzo";
            if (selectDate.Date.Month == 4)
                return "Abril";
            if (selectDate.Date.Month == 5)
                return "Mayo";
            if (selectDate.Date.Month == 6)
                return "Junio";
            if (selectDate.Date.Month == 7)
                return "Julio";
            if (selectDate.Date.Month == 8)
                return "Agosto";
            if (selectDate.Date.Month == 9)
                return "Septiembre";
            if (selectDate.Date.Month == 10)
                return "Octubre";
            if (selectDate.Date.Month == 11)
                return "Noviembre";
            if (selectDate.Date.Month == 12)
                return "Diciembre";
            return "";


        }
    }
}